package com.jy.admin.rest.sms;

import com.fqgj.common.utils.CollectionUtils;
import com.jy.admin.db.entity.SmsSendChannelEntity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: sm
 * Date: 2021/12/16
 * Time: 10:33 上午
 */
public class ChannelListResponse implements Serializable {
    private static final long serialVersionUID = -382253412967867223L;

    private Map<String, List<Item>> map = new HashMap<>();


    public ChannelListResponse(List<SmsSendChannelEntity> allChannels) {

        if (CollectionUtils.isEmpty(allChannels)) {
            return;
        }

        allChannels.forEach(channel -> {
            if (!map.containsKey(channel.getProvider())) {
                map.put(channel.getProvider(), new ArrayList<>());
            }

            List<Item> items = map.get(channel.getProvider());

            items.add(new Item()
                    .setChannelCode(channel.getChannelCode())
                    .setChannelName(channel.getName()))
            ;

            map.put(channel.getProvider(), items);
        });

    }

    public Map<String, List<Item>> getMap() {
        return map;
    }

    public ChannelListResponse setMap(Map<String, List<Item>> map) {
        this.map = map;
        return this;
    }

    private class Item {

        private String channelCode;

        private String channelName;

        public String getChannelCode() {
            return channelCode;
        }

        public Item setChannelCode(String channelCode) {
            this.channelCode = channelCode;
            return this;
        }

        public String getChannelName() {
            return channelName;
        }

        public Item setChannelName(String channelName) {
            this.channelName = channelName;
            return this;
        }
    }
}
